
#include "WinLogin.h"

WinLogin::WinLogin() : QFrame()
{
	// Fond ecran
	QLabel *image = new QLabel(this);
	image->setPixmap(QPixmap(ICONE_WP_LOGIN));

	// Login
	_login = new QLineEdit(this);
	_login->setFixedSize(150, 20);
	_login->setText("Pseudo / Adresse mail");
	_login->move(148, 290);
	QObject::connect(_login, SIGNAL(textChanged()), _login, SLOT(clear()));

	// Password
	_password = new QLineEdit(this);
//	_password->setEchoMode(QLineEdit::Password);
	_password->setFixedSize(150, 20);
	_password->setText("Password");
	_password->move(510, 290);

	// Button
	_button = new QPushButton(this);
	_button->setStyleSheet("background-image:url("BUTTON_LOGIN"); border:0;");
	_button->setFixedSize(203, 149);
	_button->move(302, 195);

	// Button + 1
	_btnPlus1 = new QPushButton(this);
	_btnPlus1->setStyleSheet("background-image:url(./Images/twitter_ico_plus.png); border:0;");
	_btnPlus1->setFixedSize(20, 20);
	_btnPlus1->move(775, 575);

	_btnPlus2 = new QPushButton(this);
	_btnPlus2->setStyleSheet("background-image:url(./Images/twitter_ico_plus2.png); border:0;");
	_btnPlus2->setFixedSize(20, 20);
	_btnPlus2->move(775, 575);
	_btnPlus2->setVisible(false);
	QObject::connect(_btnPlus1, SIGNAL(clicked()), this, SLOT(manageProxy()));
	QObject::connect(_btnPlus2, SIGNAL(clicked()), this, SLOT(manageProxy()));

	// Proxy Frame
	_proxyFrame = new QFrame(this);
	_proxyFrame->setFixedSize(200, 100);
	_proxyFrame->move(300, 360);
	_proxyFrame->setStyleSheet("background-color:yellow; border:1;");
	_proxyFrame->setVisible(false);

	// Bouton Host Proxy
	_host = new QLineEdit(_proxyFrame);
	_host->setFixedSize(150, 20);
	_host->setText("Hostname");
	_host->setStyleSheet("background-color:pink; border:1;");
	_host->move(25, 0);
	_host->setText("172.20.254.253");

	_port = new QLineEdit(_proxyFrame);
	_port->setFixedSize(150, 20);
	_port->setText("Port");
	_port->setStyleSheet("background-color:pink; border:1;");
	_port->move(25, 25);
	_port->setText("3128");

	_username = new QLineEdit(_proxyFrame);
	_username->setFixedSize(150, 20);
	_username->setText("Port");
	_username->setStyleSheet("background-color:pink; border:1;");
	_username->move(25, 50);
	_username->setText("janusk_j");

	_pw = new QLineEdit(_proxyFrame);
	_pw->setFixedSize(150, 20);
	_pw->setText("Port");
	_pw->setStyleSheet("background-color:pink; border:1;");
	_pw->move(25, 75);
	_pw->setText("yenjEgnN");

	// Bouton chargement
	 _loading = new QLabel("Chargement", this);
	 _loading->move(720, 10);
	 _loading->setVisible(false);
}

WinLogin::~WinLogin()
{
	delete _login;
	delete _password;
	delete _button;
}

QPushButton	*WinLogin::getButton() const
{
	return this->_button;
}

void WinLogin::eraseContent()
{
	this->_login->setText("");
}

void WinLogin::manageProxy()
{
	if (_btnPlus1->isVisible())
	{
		_btnPlus1->setVisible(false);
		_btnPlus2->setVisible(true);
		_proxyFrame->setVisible(true);
	}
	else
	{
		_btnPlus1->setVisible(true);
		_btnPlus2->setVisible(false);
		_proxyFrame->setVisible(false);
	}
}

QString WinLogin::getLogin() const
{
	return this->_login->text();
}

QString WinLogin::getPassword() const
{
	return this->_password->text();
}

QString WinLogin::getPHost() const
{
	return this->_host->text();
}

QString WinLogin::getPPort() const
{
	return this->_port->text();
}

QString WinLogin::getPUsername() const
{
	return this->_username->text();
}

QString WinLogin::getPPassword() const
{
	return this->_pw->text();
}

void	WinLogin::showLoading() const
{
	this->_loading->setVisible(true);
}

void	WinLogin::hideLoading() const
{
	this->_loading->setVisible(false);
}